package com.yanqu.road.entity.activity.zhenhuan.thirdProcess;

import com.yanqu.road.entity.DataObject;
import com.yanqu.road.entity.DataStatus;
import com.yanqu.road.entity.FieldTypeAnnotation;

import java.util.LinkedHashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 甄嬛三阶段花车宴会桌子
 */
@FieldTypeAnnotation(tableName = "t_c_zhenhuan_third_process_banquet_data", desc = "甄嬛三阶段花车宴会桌子")
public class CrossZhenHuanThirdProcessBanquetData extends DataObject {

    @FieldTypeAnnotation(select = true, update = true, desc = "活动id")
    private int activityId;

    @FieldTypeAnnotation(select = true, update = true, desc = "用户id")
    private long userId;
    @FieldTypeAnnotation(select = true, update = true, desc = "宴会id")
    private int banquetId;
    @FieldTypeAnnotation(desc = "宴会分")
    private long score;
    @FieldTypeAnnotation(desc = "宴会开始时间")
    private long startTime;
    @FieldTypeAnnotation(desc = "宴会类型（开宴用的道具ID）")
    private int openItemId;

    //入宴玩家
    private Map<Long, CrossZhenHuanThirdProcessBanquetUserData> joinerMap = new LinkedHashMap<>();

    /**
     * 宴会状态 0：默认，开宴中， 1：已结算  2：已结束
     */
    @FieldTypeAnnotation(desc = "宴会状态 0：默认，开宴中， 1：已结算  2：已结束")
    private int banquetState;

    public CrossZhenHuanThirdProcessBanquetData() {
    }

    public CrossZhenHuanThirdProcessBanquetData(int activityId, long userId, int banquetId, int openItemId) {
        this.activityId = activityId;
        this.userId = userId;
        this.banquetId = banquetId;
        this.openItemId = openItemId;
        setInsertOption();
    }

    public int getActivityId() {
        return activityId;
    }

    public void setActivityId(int activityId) {
        this.activityId = activityId;
    }

    public long getUserId() {
        return userId;
    }

    public void setUserId(long userId) {
        this.userId = userId;
    }

    public int getBanquetId() {
        return banquetId;
    }

    public void setBanquetId(int banquetId) {
        this.banquetId = banquetId;
    }

    public Map<Long, CrossZhenHuanThirdProcessBanquetUserData> getJoinerMap() {
        return joinerMap;
    }

    public void setJoinerMap(Map<Long, CrossZhenHuanThirdProcessBanquetUserData> joinerMap) {
        this.joinerMap = joinerMap;
    }

    public CrossZhenHuanThirdProcessBanquetUserData getJoiner(long joinerUserId) {
        return this.joinerMap.get(joinerUserId);
    }

    /**
     * 添加入宴者
     * @param joinerUserId
     * @return
     */
    public CrossZhenHuanThirdProcessBanquetUserData addJoiner(long joinerUserId) {
        Map<Long, CrossZhenHuanThirdProcessBanquetUserData> joinerMap = this.getJoinerMap();
        if (!joinerMap.containsKey(joinerUserId)) {
            CrossZhenHuanThirdProcessBanquetUserData joiner = new CrossZhenHuanThirdProcessBanquetUserData();
            joiner.setActivityId(this.getActivityId());
            joiner.setUserId(this.getUserId());
            joiner.setBanquetId(this.getBanquetId());
            joiner.setJoinUserId(joinerUserId);
            joiner.setPos(joinerMap.size() + 1);
            joiner.setCreateTime(System.currentTimeMillis());
            joiner.setInsertOption();
            this.joinerMap.put(joinerUserId, joiner);
            return joiner;
        }
        return null;
    }

    public long getScore() {
        return score;
    }

    public void setScore(long score) {
        if (this.score != score) {
            this.score = score;
            setOp(DataStatus.Update);
        }
    }

    public long getStartTime() {
        return startTime;
    }

    public void setStartTime(long startTime) {
        if (this.startTime != startTime) {
            this.startTime = startTime;
            setOp(DataStatus.Update);
        }
    }

    public int getBanquetState() {
        return banquetState;
    }

    public void setBanquetState(int banquetState) {
        if (this.banquetState != banquetState) {
            this.banquetState = banquetState;
            setOp(DataStatus.Update);
        }
    }

    public int getOpenItemId() {
        return openItemId;
    }

    public void setOpenItemId(int openItemId) {
        if (this.openItemId != openItemId) {
            this.openItemId = openItemId;
            setOp(DataStatus.Update);
        }
    }
}
